$(function () {
    findById();
});

function findById() {
    let id = sessionStorage.getItem("userId");
    console.log(id, 111);
    $.ajax({
        url: '/back/user/findById',//地址：访问后台的地址
        data: {id: id},//前端传递给后台的数据
        type: 'get',
        dataType: 'json',//是后端传递到前端的数据格式
        success: function (data) {//后端给前端的一个反馈
            console.log(data);
            setUserData(data.model);
        }

    });
}

function setUserData(data) {
    layui.use(['form'], function () {
        var form = layui.form;
        $("#L_username").val(data.username);
        $("#L_phone").val(data.phone);
        $("#L_birthday").val(data.birthday);
        $("input[name=sex][value=" + data.sex + "]").attr("checked", true);

        let hobby = data.hobby.split(",");
        for (let j = 0; j < hobby.length; j++) {
            $("input[name=hobby]").each(function () {
                if (hobby[j] == $(this).val()) {
                    $(this).prop("checked", true);
                }
            })
        }
        form.render();
    });


}